﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Threading;
using Hugo.UIPages;

namespace Hugo.UIOptions
{
    class UIInboxMessageOption : UIOption
    {
        Inbox.InboxMessage message;
        Canvas MessageCanvas;

        private static Action EmptyDelegate = delegate() { };

        Label currentSelectionLabel;

        public UIInboxMessageOption(Inbox.InboxMessage message)
            : base(message.from, Util.getBitmapSource(Properties.Resources.icon_skypecontact))
        {
            this.message = message;
            MessageCanvas = new Canvas();

            currentSelectionLabel = new Label();
            //currentSelectionLabel.FontFamily = new FontFamily("Calibri");//new Uri("pack://Hugo:,,,/Resources/"), "./#Exo_Bold");

            currentSelectionLabel.Content = "\"" + message.msg + "\"";
            currentSelectionLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

            currentSelectionLabel.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White);
            currentSelectionLabel.FontSize = 60;
            MessageCanvas.Children.Add(currentSelectionLabel);

            Canvas.SetTop(currentSelectionLabel, GlobalSettings.EffectiveScreenMiddleY);
            Canvas.SetLeft(currentSelectionLabel, 0);

        }

        DispatcherTimer timeTimer;

        public void centerLabels(Object sender, EventArgs e)
        {
            // need to rerender to get updated width
            currentSelectionLabel.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
            Canvas.SetLeft(currentSelectionLabel, GlobalSettings.EffectiveScreenMiddleX - currentSelectionLabel.ActualWidth / 2);
            timeTimer.Stop();
        }

        public override void wasSelected()
        {
            // reply to message
            UIPage p;
            if (message.from.Equals(GlobalSettings.nurseSkypeID))
            {
                p = new SkypeMessageListUI(message.from, SkypeMessageListUI.getStandardHelpOptions(), Util.getBitmapSource(Properties.Resources.icon_skypecontact));
            }
            else
            {
                p = new SkypeMessageListUI(message.from, SkypeMessageListUI.getStandardMessageOptions(), Util.getBitmapSource(Properties.Resources.icon_skypecontact));
            }
            
            MainWindow.pushPage(p);
        }

        public override System.Windows.Controls.Canvas getContent() 
        {
            timeTimer = new DispatcherTimer();
            timeTimer.Interval = TimeSpan.FromMilliseconds(0);
            timeTimer.Tick += new EventHandler(centerLabels);
            timeTimer.Start();

            return MessageCanvas;
        }

    }
}
